/*
 * 人人信用管理有限公司版权所有.
 * 
 * @Description:
 * 
 * @author: liyuliang
 * 
 * @date: 20 Apr 2017 10:44:16 am
 * 
 * 注意：本内容仅限于人人信用管理有限公司内部传阅，禁止外泄以及用于其他的商业目的.
 */

package com.rrx360.common.web.sitemesh;

import java.io.IOException;

import org.sitemesh.DecoratorSelector;
import org.sitemesh.config.MetaTagBasedDecoratorSelector;
import org.sitemesh.content.Content;
import org.sitemesh.webapp.WebAppContext;

public class RDecoratorSelector extends MetaTagBasedDecoratorSelector<WebAppContext> {

  public DecoratorSelector<WebAppContext> original;

  public RDecoratorSelector(DecoratorSelector<WebAppContext> original) {
    this.original = original;
  }

  public String[] selectDecoratorPaths(Content content, WebAppContext siteMeshContext)
      throws IOException {
    String[] templates = (String[]) siteMeshContext.getRequest().getAttribute("templates");
    if (templates != null) {
      if (templates.length == 0) {
        return new String[] {};
      }
      return templates;
    }
    String[] result = original.selectDecoratorPaths(content, siteMeshContext);
    return result;
  }

}
